package com.logistics.modules.warehouseManagement.controller;

import java.util.*;

import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.logistics.common.utils.ExcelUtiles;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.logistics.modules.warehouseManagement.entity.SeatEntity;
import com.logistics.modules.warehouseManagement.service.SeatService;
import com.logistics.common.utils.PageUtils;
import com.logistics.common.utils.R;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 
 *
 * @author HURRICANE
 * @email HURRICANE@nb.com
 * @date 2022-05-07 10:44:16
 */
@RestController
@RequestMapping("warehouseManagement/seat")
public class SeatController {

    @Autowired
    private SeatService seatService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("warehouseManagement:seat:list")
    public R list(@RequestParam Map<String, Object> params){

        PageUtils page = seatService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 导出空席位列表
     */
    @PostMapping("/exportSeatEmpty")
    @RequiresPermissions("warehouseManagement:seat:list")
    public void exportSeatEmpty(@RequestBody Map<String, Object> params,
                                        HttpServletRequest request,
                                        HttpServletResponse response){

        Boolean flag = Convert.toBool(params.get("flag"));

        // 读取数据
        List<SeatEntity> seates = CollUtil.toList(new SeatEntity());

        if (flag) {
            seates = seatService.selectByRepository();
        }


        ExcelUtiles.exportExcel(seates, "席位初始化表", "初始化仓库模板", SeatEntity.class, "测试.xls", response);

    }




    @RequestMapping("/listByStatus")
    @RequiresPermissions("warehouseManagement:seat:list")
    public R getListByStatus(@RequestParam Map<String, Object> params){

        PageUtils page = seatService.queryPageByStatus(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("warehouseManagement:seat:info")
    public R info(@PathVariable("id") Integer id){

		SeatEntity seat = seatService.getById(id);

        return R.ok().put("seat", seat);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("warehouseManagement:seat:save")
    public R save(@RequestBody SeatEntity seat){

		seatService.save(seat);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("warehouseManagement:seat:update")
    public R update(@RequestBody SeatEntity seat){

		seatService.updateById(seat);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("warehouseManagement:seat:delete")
    public R delete(@RequestBody Integer[] ids){

		seatService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
